package abd.pr1.Interface;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginWindow extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JButton login;
	private JButton nuevo;
	private JTextField usuarioText;
	private JPasswordField passText;
	
	
	public LoginWindow(){
		super();
		this.build();
		
		this.setSize(300,120);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Login");
		this.setVisible(true);
		//this.setEnabled(true);
	}
	
	private void build() {

		JPanel loginPanel= new JPanel(new BorderLayout());

			JPanel datosPanel= new JPanel(new GridLayout(2,2));
			
				JLabel usuarioLabel = new JLabel("Usuario:");
				usuarioText = new JTextField("");
				
				JLabel passLabel = new JLabel("contraseña:");
				passText = new JPasswordField();
		
				datosPanel.add(usuarioLabel);
				datosPanel.add(usuarioText);
				datosPanel.add(passLabel);
				datosPanel.add(passText);
			
			JPanel botones = new JPanel();
			
				login = new JButton("Aceptar");
				login.setActionCommand("login");
				
				nuevo = new JButton("Nuevo Usuario");
				nuevo.setActionCommand("nuevo_usuario");
			
			botones.add(login);
			botones.add(nuevo);
		
		loginPanel.add(datosPanel,BorderLayout.CENTER);
		loginPanel.add(botones,BorderLayout.SOUTH);
		
		this.add(loginPanel);
		
	}
	
	public void addListener(ActionListener a){
		login.addActionListener(a);
		nuevo.addActionListener(a);
	}

	public String getUsuario() {
		return usuarioText.getText();
	}

	public String getPassword() {
		return String.valueOf(passText.getPassword());
	}	
}
